<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>3_props简写方式</title>
  </head>
  <body>
    <!-- 准备号一个容器 -->
    <div id="test"></div>
    <div id="test2"></div>
    <div id="test3"></div>

    <!-- 引入react核心库 -->
    <script type="text/javascript" src="../js/react.development.js"></script>
    <!-- 引入react-dom，用于支持react dom操作 -->
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <!-- 引入prop-types，用于对props进行类型限制 -->
    <script type="text/javascript" src="../js/prop-types.js"></script>
    <!-- 引入babel，用于将jsx转为js -->
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <script type="text/babel">
      // 1. 创建类组件
      class Person extends React.Component {
        constructor(props) {
          super(props)
        }

        // 对标签属性类型、必要性进行限制
        static propTypes = {
          name: PropTypes.string.isRequired,
          gender: PropTypes.string,
          age: PropTypes.number
        }

        // 指定标签属性默认值
        static defaultProps = {
          gender: '未知',
          age: 18
        }

        render() {
          return (
            <ul>
              <li>姓名：{this.props.name}</li>
              <li>性别：{this.props.gender}</li>
              <li>年龄：{this.props.age + 1}</li>
            </ul>
          )
        }
      }

      // 2. 渲染组件到页面
      ReactDOM.render(<Person name="tom" />, document.getElementById('test'))
    </script>
  </body>
</html>
